//
//  Enemy.m
//  Galaxy
//
//  Created by antl on 1/29/13.
//  Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//

#import "Enemy.h"
#import "GamePlayer.h"
@implementation Enemy
@synthesize enemy,health,moveLeft;
-(id)initWithType:(ENEMY_TYPE)typeE andPosition:(CGPoint)P andSelf:(CCLayer*)parentLayer
{
    if((self=[super init]))
    {
        health=[self healthbyType:typeE];
        alpha=0;
        moveLeft=FALSE;
        enemy=[(GamePlayer*)parentLayer addImageAnimationByClass:[self getClassbyType:typeE] withZ:10];
        enemy.position=P;
        id Action1 = [enemy createAnimation];
        [enemy runAction:Action1]; 
        
    }
    return self;
}
-(Class) getClassbyType:(ENEMY_TYPE)typeE 
{
    switch (typeE) {
        case eType1:
            return [Monter_1 class];
            break;
        case eType2:
            return [Monter_2 class];
            break;
        case eType3:
            return [Monter_3 class];
            break;
        case eBoss:
            return [BOSS_1 class];
            break;                     
            
        default:
            return [Monter_1 class];
            break;
    }
}
-(int)healthbyType:(ENEMY_TYPE)typeE 
{
    switch (typeE) {
        case eType1:
            return 1;
            break;
        case eType2:
            return 2;
            break;
        case eType3:
            return 4;
            break;
        case eBoss:
            return 20;
            break;           
        default:
            return 1;
            break;
    }

}
-(void)update: (ccTime)dt
{
    
}
-(void)enemyMove
{
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    CGPoint P=enemy.position;
    int Z=3;
    if(moveLeft==FALSE){
        if(P.x>winSize.width+60)//(alpha>=kMove)
        {
            alpha=0;
            moveLeft=TRUE;
        }
    }
    else
    {
        Z=-3;
        if(P.x<-60)//(alpha>=kMove)
        {
            alpha=0;
            moveLeft=FALSE;
        }
    }
    alpha++;
    enemy.position=ccp(P.x+Z,P.y);
}
-(void)enemyShoot
{
    
}
-(void)dealloc
{
    [super dealloc];
}
@end
